package gov.pbc.nn.kjgl.jfcr.view;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import gov.pbc.nn.kjgl.entity.ComputerRoom;
import gov.pbc.nn.kjgl.entity.ComputerRoomArea;
import gov.pbc.nn.kjgl.jfcr.dao.ComputerRoomDao;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Page;

/**
 * 机房操作的业务逻辑
 * 
 * @author jack.zhao
 * 
 */
@Component("computerRoomPR")
public class ComputerRoomPR {

	@Autowired
	private ComputerRoomDao computerRoomDao;

	/**
	 * 分页并返回给前台
	 * 
	 * @param page
	 */
	@DataProvider
	public void getComputerRoom(Page<ComputerRoom> page) {
		computerRoomDao.getComputerRoomPage(page);
	}

	/**
	 * 使用dao根据id得到ComputerRoomArea
	 * 
	 * @param id
	 * @return
	 */
	@DataProvider
	public List<ComputerRoomArea> geteChildEntityBycrId(String id) {
		return computerRoomDao.getBycId(id);
	}

	/**
	 * 使用dao更新ComputerRoom
	 * 
	 * @param lists
	 */
	@DataResolver
	@Transactional
	public void updateEntityList(Collection<ComputerRoom> lists) {
		computerRoomDao.updateEntitys(lists);
	}

	/**
	 * 使用dao根据id更新ComputerRoomArea
	 * 
	 * @param lists
	 * @param pid
	 */
	@DataResolver
	@Transactional
	public void updateEntity(Collection<ComputerRoomArea> lists, String pid) {
		if (!StringUtils.isEmpty(pid)) {
			computerRoomDao.updateChild(lists, pid);
		}
	}

	/**
	 * 使用dao根据id删除ComputerRoomArea
	 * 
	 * @param parameter
	 */
	@Expose
	@Transactional
	public void delete(Map<String, Object> parameter) {
		String id = (String) parameter.get("id");
		if (!StringUtils.isEmpty(id)) {
			computerRoomDao.delete(id, ComputerRoomArea.class);
		}
	}
}
